<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="文档管理">
<meta name="author" content="文档管理">
<title>如何嵌入子模板 文档管理</title>
<link href="./assets/css/bootstrap.min.css" rel="stylesheet">
<!-- Documentation extras -->
<link href="./assets/css/docs.css" rel="stylesheet">
<link href="./assets/css/style.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/highlight.js/7.3/styles/github.min.css" rel="stylesheet">
<style>
body{font-family:"ff-tisa-web-pro-1","ff-tisa-web-pro-2","Lucida Grande","Helvetica Neue",Helvetica,Arial,"Hiragino Sans GB","Hiragino Sans GB W3","WenQuanYi Micro Hei",sans-serif;}
h1, .h1, h2, .h2, h3, .h3, h4, .h4, .lead {font-family:"ff-tisa-web-pro-1","ff-tisa-web-pro-2","Lucida Grande","Helvetica Neue",Helvetica,Arial,"Hiragino Sans GB","Hiragino Sans GB W3","Microsoft YaHei UI","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
pre code { background: transparent; }
@media (min-width: 768px) {
    .bs-docs-home .bs-social, 
    .bs-docs-home .bs-masthead-links {
      margin-left: 0;
    }
}
.bs-docs-section p {
	line-height: 2;
}
.bs-docs-section p.lead {
	line-height: 1.4;
}
</style>
<!--[if lt IE 9]><script src="../docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
  <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
  <script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<!-- Favicons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../docs-assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="shortcut icon" href="../docs-assets/ico/favicon.png">
  </head>
  <body>
    <a class="sr-only" href="#content">Skip to main content</a>

    <!-- Docs master nav -->
    <header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
  <div class="container">
    <div class="navbar-header">
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a href="./overview.html" class="navbar-brand">文档管理</a>
    </div>
    <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
      <ul class="nav navbar-nav">
       		<li  ><a href="overview.html">简介</a></li>
            <li ><a href="download.html">下载</a></li>
            <li ><a href="userguide.html">开发指南</a></li>
            <li ><a href="config.html">配置指南</a></li>
            <li ><a href="syntax.html">语法指南</a></li>
            <li ><a href="integrate.html">Web 框架集成</a></li>
            <!--
            <li ><a href="example.html">例子</a></li>
            -->
            <li ><a href="faq.html" class="selected">FAQ</a></li>
            <li ><a href="about.html">关于</a></li>
      </ul>
    </nav>
  </div>
</header>
    <!-- Docs page layout -->
    <div class="bs-header" id="content">
      <div class="container">
        <h2>如何嵌入子模板</h2>
        <p></p>
      </div>
    </div>
	<a href="#top" id="toTop"></a>
    <!-- Callout for the old docs link -->
    <div class="container bs-docs-container">
      <div class="row">
        <div class="col-md-3">
          <div class="bs-sidebar hidden-print" role="complementary">
            <ul class="nav bs-sidenav">
            <li><a href="#x484753138">1 jetbrick-template 中如何嵌入子模板？（父子间参数传递）</a></li>
            <li><a href="#x896136284">&nbsp&nbsp1.1 最常规的做法是</a></li>
            <li><a href="#x1607061973">&nbsp&nbsp1.2 对 include() 函数返回值处理的应用</a></li>
            <li><a href="#x1786829436">&nbsp&nbsp1.3 父子模板间传递参数</a></li>
            </ul>
          </div>
        </div>
	        <div class="col-md-9" role="main">
	         <div class="bs-docs-section">
	           <h1 id="x484753138" class="page-header"><span>1 jetbrick-template 中如何嵌入子模板？（父子间参数传递）</span></h1>
<p>在 jetbrick-template 中我们有:</p> 
<ul> 
 <li><code>#include(file, ...)</code> 指令</li> 
 <li><code>include(file, ...)</code> 函数</li> 
 <li><code>read(file, ...)</code> 函数 - 用于嵌入纯文本文件</li> 
</ul>
<h2 id="x896136284" class="page-header"><span>1.1 最常规的做法是</span></h2>
<h3 id="x1273322146" class="page-header"><span>1.1.1 include 静态文件名</span></h3> 
<div class="highlight">
 <pre><code class="language-html">#include(&quot;/include/header.jetx&quot;)
${include(&quot;/include/header.jetx&quot;)}
</code></pre>
</div>
<h3 id="x333569747" class="page-header"><span>1.1.2 include 动态文件名</span></h3> 
<div class="highlight">
 <pre><code class="language-html">#define(String url)
#include(url)
${include(url)}
</code></pre>
</div> 
<blockquote>
 <p><strong>注意</strong>： <code>#include</code> 指令和 <code>include()</code> 函数的区别是：</p> 
 <ul> 
  <li><code>#include</code> 指令直接将内容输出到原始的 Stream/Writer 里面，效率高。</li> 
  <li><code>include()</code> 函数将内容缓存到一个 String 中返回，可以对返回值进行进一步处理。</li> 
  <li><code>#include</code> 指令如果包含的是静态文件名，那么会检查文件是否存在。<code>include()</code> 函数不会做任何检查。</li> 
 </ul> 
</blockquote>
<h2 id="x1607061973" class="page-header"><span>1.2 对 include() 函数返回值处理的应用</span></h2> 
<div class="highlight">
 <pre><code class="language-html">下面内容全部转为大写字母
${include(&quot;ascii.jetx&quot;).toUpperCase()}
</code></pre>
</div>
<p>输出内容</p> 
<div class="highlight">
 <pre><code class="language-html">ABCDEFG...
</code></pre>
</div>
<h2 id="x1786829436" class="page-header"><span>1.3 父子模板间传递参数</span></h2>
<p>我们有以下几种方式可以在父子模板间传递参数</p> 
<ul> 
 <li>父模板的 <code>JetContext</code> 自动传递给子模板。</li> 
 <li><code>#set</code> 指令会修改当前模板的 <code>JetContext</code>，同时也会影响子模板。</li> 
 <li><code>#include</code> 指令和 <code>include()</code> 函数的第二个参数可以传递一个单独的 Map 对象给子模板。</li> 
 <li>子模板通过 <code>#put</code> 指令向父模板返回数据。</li> 
</ul>
<h3 id="x635726137" class="page-header"><span>1.3.1 include 父传子参数例子：</span></h3>
<p>子模板 sub.inc.jetx</p> 
<div class="highlight">
 <pre><code class="language-html">Hello from sub, parent name is ${parentName}.
</code></pre>
</div>
<p>父模板 parent.jetx</p> 
<div class="highlight">
 <pre><code class="language-html">This is parent.
#include(&quot;sub.inc.jetx&quot;, {&quot;parentName&quot;, &quot;PARENT_NAME&quot;})
</code></pre>
</div>
<p>显示结果如下：</p> 
<div class="highlight">
 <pre><code class="language-html">This is parent.
Hello from sub, parent name is PARENT_NAME.
</code></pre>
</div>
<h3 id="x446365909" class="page-header"><span>1.3.2 #put 子传父参数例子：</span></h3>
<p>子模板 sub.inc.jetx</p> 
<div class="highlight">
 <pre><code class="language-html">Hello from sub.
#put(&quot;age&quot;, 1234567890);
</code></pre>
</div>
<p>父模板 parent.jetx</p> 
<div class="highlight">
 <pre><code class="language-html">This is parent.
#include(&quot;sub.inc.jetx&quot;)
sub.age = ${context.age}
</code></pre>
</div>
<p>显示结果如下：</p> 
<div class="highlight">
 <pre><code class="language-html">This is parent.
Hello from sub.
sub.age = 1234567890
</code></pre>
</div>
           	</div>
           </div>
		</div> 
 	</div>
    <!-- Footer
    ================================================== -->
    <footer class="bs-footer" role="contentinfo">
      <div class="container">
        <ul class="footer-links">
          <li>当前版本： v0.0.3</li>
          <li class="muted">&middot;</li>
          <li><a href="http://v2.bootcss.com/">Bootstrap 2.3.2 中文文档</a></li>
          <li class="muted">&middot;</li>
          <li><a href="http://www.bootcss.com">Bootstrap中文网</a></li>
          <li class="muted">&middot;</li>
          <li><a href="http://blog.getbootstrap.com">官方博客</a></li>
          <li class="muted">&middot;</li>
          <li><a href="https://github.com/twbs/bootstrap/issues?state=open">Issues</a></li>
          <li class="muted">&middot;</li>
          <li><a href="https://github.com/twbs/bootstrap/releases">Releases</a></li>
        </ul>
      </div>
    </footer>

    <!-- JS and analytics only. -->
<script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<script src="./assets/js/bootstrap.js"></script>
<script src="http://cdn.bootcss.com/holder/2.0/holder.min.js"></script>
<script src="http://cdn.bootcss.com/highlight.js/7.3/highlight.min.js"></script>
<script >hljs.initHighlightingOnLoad();</script>
<script src="./assets/js/application.js"></script>
<script src="./assets/js/jquery.scrollToTop.min.js"></script>
<script text="javascript/text">
	$(document).ready(function(){
		$("#toTop").scrollToTop(1000);
  		$("table").addClass("table table-bordered");
  	});
</script>
  </body>
</html>
